function todoReducer(data){
  function addItem(newItem){
    return data.concat(newItem)
  }
  function removeItem(id){
    return data.filter(item => item.id !== id)
  }
  function changeCompeleted(id){
    return data.map((item) => {
      if(item.id === id) {
        item.compeleted = !item.compeleted
      }
      return item
    });
  }

  return {
    addItem,
    removeItem,
    changeCompeleted
  }
}

export default todoReducer
